<?php if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/margins')): ?>

<fieldset id="my-fieldset">
	<div class="grid"> 
		<table cellspacing="0" class="data" width="100%">
			<thead> 
                <tr class="headings"> 
	            	<th class="a-center"><span class="nobr"><?php echo $this->__('Product'); ?></span></th> 
	            	<th class="a-center"><span class="nobr"><?php echo $this->__('Ordered qty'); ?></span></th> 
	            	<th class="a-center"><span class="nobr"><?php echo $this->__('Unit Cost'); ?></span></th> 
	            	<th class="a-center"><span class="nobr"><?php echo $this->__('Unit Price'); ?></span></th> 
	            	<th class="a-center"><span class="nobr"><?php echo $this->__('Total Margin'); ?></span></th> 
	            	<th class="a-center"><span class="nobr"><?php echo $this->__('Total Margin %'); ?></span></th> 
	            </tr>
	        </thead>
	        <tbody>
        		<?php foreach($this->getItems() as $item): ?>
					<tr>
						<td><?php echo $item->getName(); ?></td>
						<td align="center"><?php echo (int)$item->getqty_ordered(); ?></td>
						<td class="a-right"><?php echo Mage::app()->getStore()->getBaseCurrency()->format($item->getData(mage::helper('AdvancedStock/MagentoVersionCompatibility')->getSalesOrderItemCostColumnName())); ?></td>
						<td class="a-right"><?php echo Mage::app()->getStore()->getBaseCurrency()->format($item->getbase_price()); ?></td>
						<td class="a-right"><?php echo Mage::app()->getStore()->getBaseCurrency()->format($item->GetMargin()); ?></td>
						<td class="a-right"><?php echo number_format($item->GetMarginPercent(), 2); ?> %</td>
					</tr>        		
        		<?php endforeach; ?>
	        </tbody>
	        <tfoot>
	        		<tr>
	        			<td colspan="4"></td>
	        			<td class="a-right"><b><?php echo Mage::app()->getStore()->getBaseCurrency()->format($this->getOrder()->GetMargin()); ?></b></td>
	        			<td class="a-right"><b><?php echo number_format($this->getOrder()->GetMarginPercent(), 2); ?> %</b></td>
	        		</tr>
	        </tfoot>
		</table>
	</div>
</fieldset>

<?php else: ?>

	<?php echo $this->__('Access denied'); ?>

<?php endif; ?>